static string JS_client_client = 
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief AvocadoShell client API\n"
  "///\n"
  "/// @file\n"
  "///\n"
  "/// DISCLAIMER\n"
  "///\n"
  "/// Copyright 2012 triagens GmbH, Cologne, Germany\n"
  "///\n"
  "/// Licensed under the Apache License, Version 2.0 (the \"License\");\n"
  "/// you may not use this file except in compliance with the License.\n"
  "/// You may obtain a copy of the License at\n"
  "///\n"
  "///     http://www.apache.org/licenses/LICENSE-2.0\n"
  "///\n"
  "/// Unless required by applicable law or agreed to in writing, software\n"
  "/// distributed under the License is distributed on an \"AS IS\" BASIS,\n"
  "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
  "/// See the License for the specific language governing permissions and\n"
  "/// limitations under the License.\n"
  "///\n"
  "/// Copyright holder is triAGENS GmbH, Cologne, Germany\n"
  "///\n"
  "/// @author Achim Brandt\n"
  "/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                  global variables\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief default collection for saving queries\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "var DEFAULT_QUERY_COLLECTION = \"query\";\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief help texts\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "var HELP = \"\";\n"
  "var helpQueries = \"\";\n"
  "var helpAvocadoDatabase = \"\";\n"
  "var helpAvocadoCollection = \"\";\n"
  "var helpAvocadoQueryCursor = \"\";\n"
  "var helpAvocadoStoredStatement = \"\";\n"
  "var helpAvocadoStatement = \"\";\n"
  "var helpExtended = \"\";\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                 private functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return a formatted type string for object\n"
  "/// \n"
  "/// If the object has an id, it will be included in the string.\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function TRI_GetIdString (object, typeName) {\n"
  "  var result = \"[object \" + typeName;\n"
  "  \n"
  "  if (object._id) {\n"
  "    result += \":\" + object._id;\n"
  "  }\n"
  "  else if (object.data && object.data._id) {\n"
  "    result += \":\" + object.data._id;\n"
  "  }\n"
  "\n"
  "  result += \"]\";\n"
  "\n"
  "  return result;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief handles error results\n"
  "/// \n"
  "/// throws an exception in case of an an error\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function TRI_CheckRequestResult (requestResult) {\n"
  "  if (requestResult == undefined) {    \n"
  "    requestResult = {\n"
  "      \"error\" : true,\n"
  "      \"code\"  : 0,\n"
  "      \"errorNum\" : 0,\n"
  "      \"errorMessage\" : \"Unknown error. Request result is empty\"\n"
  "    }    \n"
  "  }\n"
  "  \n"
  "  if (requestResult[\"error\"] != undefined && requestResult[\"error\"]) {    \n"
  "    throw new AvocadoError(requestResult);\n"
  "  }  \n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief create a formatted headline text \n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function TRI_CreateHelpHeadline (text) {\n"
  "  var x = parseInt(Math.abs(78 - text.length) / 2);\n"
  "  \n"
  "  var p = \"\";\n"
  "  for (var i = 0; i < x; ++i) {\n"
  "    p += \"-\";\n"
  "  }\n"
  "  \n"
  "  return \"\\n\" + p + \" \" + text + \" \" + p + \"\\n\";\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                  public functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief turn off pretty printing\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function print_plain (data) {\n"
  "  var p = PRETTY_PRINT;\n"
  "  PRETTY_PRINT = false;\n"
  "  var c;\n"
  "  if (typeof(COLOR_OUTPUT) != undefined) {\n"
  "    c = COLOR_OUTPUT;\n"
  "    COLOR_OUTPUT = undefined;\n"
  "  }\n"
  "  \n"
  "  try {\n"
  "    print(data);\n"
  "    PRETTY_PRINT = p;\n"
  "    if (typeof(c) != undefined) {\n"
  "      COLOR_OUTPUT = c;\n"
  "    }   \n"
  "  }\n"
  "  catch (e) {\n"
  "    PRETTY_PRINT = p;\n"
  "    if (typeof(c) != undefined) {\n"
  "      COLOR_OUTPUT = c;\n"
  "    }   \n"
  "    throw e.message;    \n"
  "  }  \n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief start pretty printing\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function start_pretty_print () {\n"
  "  print(\"use pretty printing\");\n"
  "  PRETTY_PRINT=true;\n"
  "  return undefined;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief stop pretty printing\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function stop_pretty_print () {\n"
  "  print(\"stop pretty printing\");\n"
  "  PRETTY_PRINT=false;\n"
  "  return undefined;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief start pretty printing with optional color\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function start_color_print (color) {\n"
  "  if (typeof(color) == \"string\") {\n"
  "    COLOR_OUTPUT = color;\n"
  "  }\n"
  "  else {\n"
  "    COLOR_OUTPUT = COLOR_BRIGHT;\n"
  "  }\n"
  "  print(\"start \" + COLOR_OUTPUT + \"color\" + COLOR_OUTPUT_RESET + \" printing\");\n"
  "  return undefined;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief stop pretty printing\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function stop_color_print () {\n"
  "  print(\"stop color printing\");\n"
  "  COLOR_OUTPUT = undefined;\n"
  "  return undefined;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief print the overall help\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function help () {\n"
  "  print(HELP);\n"
  "  print(helpQueries);\n"
  "  print(helpAvocadoDatabase);\n"
  "  print(helpAvocadoCollection);\n"
  "  print(helpAvocadoStatement);\n"
  "  print(helpAvocadoQueryCursor);\n"
  "  print(helpExtended);\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                 Module \"internal\"\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief change internal.output to shell output\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "ModuleCache[\"/internal\"].exports.output = TRI_SYS_OUTPUT;\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief log function\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "ModuleCache[\"/internal\"].exports.log = function(level, msg) {\n"
  "  internal.output(level, \": \", msg, \"\\n\");\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief starts the pager\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "ModuleCache[\"/internal\"].exports.start_pager = SYS_START_PAGER;\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief stops the pager\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "ModuleCache[\"/internal\"].exports.stop_pager = SYS_STOP_PAGER;\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                      AvocadoError\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                      constructors and destructors\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief constructor\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function AvocadoError (error) {\n"
  "  this.error = error.error;\n"
  "  this.code = error.code;\n"
  "  this.errorNum = error.errorNum;\n"
  "  this.errorMessage = error.errorMessage;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                 private functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief prints an error\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoError.prototype._PRINT = function() {\n"
  "  internal.output(this.toString());\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief toString function\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoError.prototype.toString = function() {\n"
  "  var result = \"\";\n"
  "  if (typeof(COLOR_BRIGHT) != \"undefined\") {\n"
  "    result = COLOR_BRIGHT + \"Error: \" + COLOR_OUTPUT_RESET;\n"
  "  }\n"
  "  else  {\n"
  "    result = \"Error: \";\n"
  "  }\n"
  "\n"
  "  result += \"[\" + this.code + \":\" + this.errorNum + \"] \" + this.errorMessage;\n"
  "  \n"
  "  return result;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief prints an error\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoError.prototype.toString = function() {\n"
  "  var errorNum = this.errorNum;\n"
  "  var errorMessage = this.errorMessage;\n"
  "\n"
  "  return \"[AvocadoError \" + errorNum + \": \" + errorMessage + \"]\";\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                   AvocadoDatabase\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                      constructors and destructors\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief constructor\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function AvocadoDatabase (connection) {\n"
  "  this._connection = connection;\n"
  "  this._collectionConstructor = AvocadoCollection;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                 private functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief help for AvocadoDatabase\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "helpAvocadoDatabase = TRI_CreateHelpHeadline(\"AvocadoDatabase help\") +\n"
  "'AvocadoDatabase constructor:                                        ' + \"\\n\" +\n"
  "' > db = new AvocadoDatabase(connection);                            ' + \"\\n\" +\n"
  "'                                                                    ' + \"\\n\" +\n"
  "'Administration Functions:                                           ' + \"\\n\" +\n"
  "'  _help();                       this help                          ' + \"\\n\" +\n"
  "'                                                                    ' + \"\\n\" +\n"
  "'Collection Functions:                                               ' + \"\\n\" +\n"
  "'  _collections()                 list all collections               ' + \"\\n\" +\n"
  "'  _collection(<identifier>)      get collection by identifier/name  ' + \"\\n\" +\n"
  "'  _create(<name>, <props>)       creates a new collection           ' + \"\\n\" +\n"
  "'  _truncate(<name>)              delete all documents               ' + \"\\n\" +\n"
  "'  _drop(<name>)                  delete a collection                ' + \"\\n\" +\n"
  "'                                                                    ' + \"\\n\" +\n"
  "'Document Functions:                                                 ' + \"\\n\" +\n"
  "'  _document(<id>)                 get document by handle            ' + \"\\n\" +\n"
  "'  _replace(<id>, <data>)          over-writes document              ' + \"\\n\" +\n"
  "'  _remove(<id>)                   deletes document                  ' + \"\\n\" +\n"
  "'                                                                    ' + \"\\n\" +\n"
  "'Query Functions:                                                    ' + \"\\n\" +\n"
  "'  _createStatement(<data>);      create and return select query     ' + \"\\n\" +\n"
  "'                                                                    ' + \"\\n\" +\n"
  "'Attributes:                                                         ' + \"\\n\" +\n"
  "'  <collection names>             collection with the given name     ';\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief print the help for AvocadoDatabase\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoDatabase.prototype._help = function () {  \n"
  "  print(helpAvocadoDatabase);\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return a string representation of the database object\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoDatabase.prototype.toString = function () {  \n"
  "  return \"[object AvocadoDatabase]\";\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                              collection functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return all collections from the database\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoDatabase.prototype._collections = function () {\n"
  "  var requestResult = this._connection.GET(\"/_api/collection\");\n"
  "  \n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  if (requestResult[\"collections\"] != undefined) {\n"
  "    var collections = requestResult[\"collections\"];\n"
  "    var result = []\n"
  "    \n"
  "    // add all collentions to object\n"
  "    for (var i = 0;  i < collections.length;  ++i) {\n"
  "      var collection = new this._collectionConstructor(this, collections[i]);\n"
  "\n"
  "      this[collection._name] = collection;\n"
  "      result.push(collection);\n"
  "    }\n"
  "      \n"
  "    return result;\n"
  "  }\n"
  "  \n"
  "  return undefined;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return a single collection, identified by its id or name\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoDatabase.prototype._collection = function (id) {\n"
  "  var requestResult = this._connection.GET(\"/_api/collection/\" + encodeURIComponent(id));\n"
  "  \n"
  "  // return null in case of not found\n"
  "  if (requestResult != null\n"
  "      && requestResult.error == true \n"
  "      && requestResult.errorNum == internal.errors.ERROR_AVOCADO_COLLECTION_NOT_FOUND.code) {\n"
  "    return null;\n"
  "  }\n"
  "\n"
  "  // check all other errors and throw them\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  var name = requestResult[\"name\"];\n"
  "\n"
  "  if (name != undefined) {\n"
  "    return this[name] = new this._collectionConstructor(this, requestResult);\n"
  "  }\n"
  "  \n"
  "  return undefined;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief creates a new collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoDatabase.prototype._create = function (name, properties) {\n"
  "  var body = {\n"
  "    \"name\" : name\n"
  "  };\n"
  "\n"
  "  if (properties != null) {\n"
  "    if (properties.hasOwnProperty(\"waitForSync\")) {\n"
  "      body.waitForSync = properties.waitForSync;\n"
  "    }\n"
  "\n"
  "    if (properties.hasOwnProperty(\"journalSize\")) {\n"
  "      body.journalSize = properties.journalSize;\n"
  "    }\n"
  "  }\n"
  "\n"
  "  var requestResult = this._connection.POST(\"/_api/collection\", JSON.stringify(body));\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  var name = requestResult[\"name\"];\n"
  "\n"
  "  if (name != undefined) {\n"
  "    return this[name] = new this._collectionConstructor(this, requestResult);\n"
  "  }\n"
  "  \n"
  "  return undefined;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief truncates a collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoDatabase.prototype._truncate = function (id) {\n"
  "  for (var name in this) {\n"
  "    if (this.hasOwnProperty(name)) {\n"
  "      var collection = this[name];\n"
  "\n"
  "      if (collection instanceof this._collectionConstructor) {\n"
  "        if (collection._id == id || collection._name == id) {\n"
  "          return collection.truncate();\n"
  "        }\n"
  "      }\n"
  "    }\n"
  "  }\n"
  "\n"
  "  return undefined;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief drops a collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoDatabase.prototype._drop = function (id) {\n"
  "  for (var name in this) {\n"
  "    if (this.hasOwnProperty(name)) {\n"
  "      var collection = this[name];\n"
  "\n"
  "      if (collection instanceof this._collectionConstructor) {\n"
  "        if (collection._id == id || collection._name == id) {\n"
  "          return collection.drop();\n"
  "        }\n"
  "      }\n"
  "    }\n"
  "  }\n"
  "\n"
  "  return undefined;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                document functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return a single document from the collection, identified by its id\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoDatabase.prototype._document = function (id) {\n"
  "  var rev = null;\n"
  "  var requestResult;\n"
  "\n"
  "  if (id.hasOwnProperty(\"_id\")) {\n"
  "    if (id.hasOwnProperty(\"_rev\")) {\n"
  "      rev = id._rev;\n"
  "    }\n"
  "\n"
  "    id = id._id;\n"
  "  }\n"
  "\n"
  "  if (rev == null) {\n"
  "    requestResult = this._connection.GET(\"/document/\" + id);\n"
  "  }\n"
  "  else {\n"
  "    requestResult = this._connection.GET(\"/document/\" + id, {'if-match' : '\"' + rev + '\"' });\n"
  "  }\n"
  "\n"
  "  if (requestResult != null\n"
  "      && requestResult.error == true \n"
  "      && requestResult.errorNum == internal.errors.ERROR_AVOCADO_COLLECTION_NOT_FOUND.code) {\n"
  "    var s = id.split(\"/\");\n"
  "\n"
  "    if (s.length != 2) {\n"
  "      requestResult.errorNum = internal.errors.ERROR_AVOCADO_DOCUMENT_HANDLE_BAD.code;\n"
  "    }\n"
  "\n"
  "    throw new AvocadoError(requestResult);\n"
  "  }\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return requestResult;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief delete a document in the collection, identified by its id\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoDatabase.prototype._remove = function (id, overwrite) {\n"
  "  var rev = null;\n"
  "  var requestResult;\n"
  "\n"
  "  if (id.hasOwnProperty(\"_id\")) {\n"
  "    if (id.hasOwnProperty(\"_rev\")) {\n"
  "      rev = id._rev;\n"
  "    }\n"
  "\n"
  "    id = id._id;\n"
  "  }\n"
  "\n"
  "  var policy = \"\";\n"
  "\n"
  "  if (overwrite) {\n"
  "    policy = \"?policy=last\";\n"
  "  }\n"
  "\n"
  "  if (rev == null) {\n"
  "    requestResult = this._connection.DELETE(\"/document/\" + id + policy);\n"
  "  }\n"
  "  else {\n"
  "    requestResult = this._connection.DELETE(\"/document/\" + id + policy, {'if-match' : '\"' + rev + '\"' });\n"
  "  }\n"
  "\n"
  "  if (requestResult != null && requestResult.error == true) {\n"
  "    var s = id.split(\"/\");\n"
  "\n"
  "    if (s.length != 2) {\n"
  "      requestResult.errorNum = internal.errors.ERROR_AVOCADO_DOCUMENT_HANDLE_BAD.code;\n"
  "    }\n"
  "\n"
  "    if (overwrite) {\n"
  "      if (requestResult.errorNum == internal.errors.ERROR_AVOCADO_DOCUMENT_NOT_FOUND.code) {\n"
  "        return false;\n"
  "      }\n"
  "    }\n"
  "\n"
  "    throw new AvocadoError(requestResult);\n"
  "  }\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return true;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief update a document in the collection, identified by its id\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoDatabase.prototype._replace = function (id, data, overwrite) { \n"
  "  var rev = null;\n"
  "  var requestResult;\n"
  "\n"
  "  if (id.hasOwnProperty(\"_id\")) {\n"
  "    if (id.hasOwnProperty(\"_rev\")) {\n"
  "      rev = id._rev;\n"
  "    }\n"
  "\n"
  "    id = id._id;\n"
  "  }\n"
  "\n"
  "  var policy = \"\";\n"
  "\n"
  "  if (overwrite) {\n"
  "    policy = \"?policy=last\";\n"
  "  }\n"
  "\n"
  "  if (rev == null) {\n"
  "    requestResult = this._connection.PUT(\"/document/\" + id + policy, JSON.stringify(data));\n"
  "  }\n"
  "  else {\n"
  "    requestResult = this._connection.PUT(\"/document/\" + id + policy, JSON.stringify(data), {'if-match' : '\"' + rev + '\"' });\n"
  "  }\n"
  "\n"
  "  if (requestResult != null && requestResult.error == true) {\n"
  "    var s = id.split(\"/\");\n"
  "\n"
  "    if (s.length != 2) {\n"
  "      requestResult.errorNum = internal.errors.ERROR_AVOCADO_DOCUMENT_HANDLE_BAD.code;\n"
  "    }\n"
  "\n"
  "    throw new AvocadoError(requestResult);\n"
  "  }\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return requestResult;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                   query functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief factory method to create a new statement\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoDatabase.prototype._createStatement = function (data) {  \n"
  "  return new AvocadoStatement(this, data);\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                      AvocadoEdges\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                      constructors and destructors\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief constructor\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function AvocadoEdges (connection) {\n"
  "  this._connection = connection;\n"
  "  this._collectionConstructor = AvocadoEdgesCollection;\n"
  "}\n"
  "\n"
  "AvocadoEdges.prototype = new AvocadoDatabase();\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                 private functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief help for AvocadoEdges\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "helpAvocadoEdges = TRI_CreateHelpHeadline(\"AvocadoEdges help\") +\n"
  "'AvocadoEdges constructor:                                           ' + \"\\n\" +\n"
  "' > edges = new AvocadoEdges(connection);                            ' + \"\\n\" +\n"
  "'                                                                    ' + \"\\n\" +\n"
  "'Administration Functions:                                           ' + \"\\n\" +\n"
  "'  _help();                       this help                          ' + \"\\n\" +\n"
  "'                                                                    ' + \"\\n\" +\n"
  "'Attributes:                                                         ' + \"\\n\" +\n"
  "'  <collection names>             collection with the given name     ';\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief print the help for AvocadoEdges\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoEdges.prototype._help = function () {  \n"
  "  print(helpAvocadoEdges);\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return a string representation of the database object\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoEdges.prototype.toString = function () {  \n"
  "  return \"[object AvocadoEdges]\";\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                 AvocadoCollection\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                      constructors and destructors\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief constructor\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function AvocadoCollection (database, data) {\n"
  "  this._database = database;\n"
  "\n"
  "  if (typeof data === \"string\") {\n"
  "    this._name = data;\n"
  "  }\n"
  "  else if (data != null) {\n"
  "    this._id = data.id;\n"
  "    this._name = data.name;\n"
  "    this._status = data.status;\n"
  "  }\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                         constants\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief collection is corrupted\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.STATUS_CORRUPTED = 0;\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief collection is new born\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.STATUS_NEW_BORN = 1;\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief collection is unloaded\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.STATUS_UNLOADED = 2;\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief collection is loaded\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.STATUS_LOADED = 3;\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief collection is unloading\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.STATUS_UNLOADING = 4;\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief collection is deleted\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.STATUS_DELETED = 5;\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                 private functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief help for AvocadoCollection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "helpAvocadoCollection = TRI_CreateHelpHeadline(\"AvocadoCollection help\") +\n"
  "'AvocadoCollection constructor:                                      ' + \"\\n\" +\n"
  "' > col = db.mycoll;                                                 ' + \"\\n\" +\n"
  "' > col = db._create(\"mycoll\");                                      ' + \"\\n\" +\n"
  "'                                                                    ' + \"\\n\" +\n"
  "'Administration Functions:                                           ' + \"\\n\" +\n"
  "'  name()                          collection name                   ' + \"\\n\" +\n"
  "'  status()                        status of the collection          ' + \"\\n\" +\n"
  "'  truncate()                      delete all documents              ' + \"\\n\" +\n"
  "'  properties()                    show collection properties        ' + \"\\n\" +\n"
  "'  drop()                          delete a collection               ' + \"\\n\" +\n"
  "'  load()                          load a collection into memeory    ' + \"\\n\" +\n"
  "'  unload()                        unload a collection from memory   ' + \"\\n\" +\n"
  "'  rename(new-name)                renames a collection              ' + \"\\n\" +\n"
  "'  refresh()                       refreshes the status and name     ' + \"\\n\" +\n"
  "'  _help();                        this help                         ' + \"\\n\" +\n"
  "'                                                                    ' + \"\\n\" +\n"
  "'Document Functions:                                                 ' + \"\\n\" +\n"
  "'  count()                         number of documents               ' + \"\\n\" +\n"
  "'  save(<data>)                    create document and return handle ' + \"\\n\" +\n"
  "'  document(<id>)                  get document by handle            ' + \"\\n\" +\n"
  "'  replace(<id>, <data>)           over-writes document              ' + \"\\n\" +\n"
  "'  delete(<id>)                    deletes document                  ' + \"\\n\" +\n"
  "'                                                                    ' + \"\\n\" +\n"
  "'Attributes:                                                         ' + \"\\n\" +\n"
  "'  _database                       database object                   ' + \"\\n\" +\n"
  "'  _id                             collection identifier             ';\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return a string representation of the collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.toString = function () {  \n"
  "  return TRI_GetIdString(this, \"AvocadoCollection\");\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief prints the collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype._PRINT = function () {  \n"
  "  var status = \"unknown\";\n"
  "\n"
  "  switch (this.status()) {\n"
  "    case AvocadoCollection.STATUS_NEW_BORN: status = \"new born\"; break;\n"
  "    case AvocadoCollection.STATUS_UNLOADED: status = \"unloaded\"; break;\n"
  "    case AvocadoCollection.STATUS_UNLOADING: status = \"unloading\"; break;\n"
  "    case AvocadoCollection.STATUS_LOADED: status = \"loaded\"; break;\n"
  "    case AvocadoCollection.STATUS_CORRUPTED: status = \"corrupted\"; break;\n"
  "    case AvocadoCollection.STATUS_DELETED: status = \"deleted\"; break;\n"
  "  }\n"
  "  \n"
  "  internal.output(\"[AvocadoCollection \", this._id, \", \\\"\", this.name(), \"\\\" (status \" + status + \")]\");\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief print the help for AvocadoCollection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype._help = function () {  \n"
  "  print(helpAvocadoCollection);\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                  public functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief returns the name of a collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.name = function () {\n"
  "  if (this._name == null) {\n"
  "    this.refresh();\n"
  "  }\n"
  "\n"
  "  return this._name;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief returns the status of a collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.status = function () {\n"
  "  if (this._status == null) {\n"
  "    this.refresh();\n"
  "  }\n"
  "\n"
  "  return this._status;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief gets or sets the properties of a collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.properties = function (properties) {\n"
  "  var requestResult;\n"
  "\n"
  "  if (properties == null) {\n"
  "    requestResult = this._database._connection.GET(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/properties\");\n"
  "\n"
  "    TRI_CheckRequestResult(requestResult);\n"
  "  }\n"
  "  else {\n"
  "    var body = {};\n"
  "\n"
  "    if (properties.hasOwnProperty(\"waitForSync\")) {\n"
  "      body.waitForSync = properties.waitForSync;\n"
  "    }\n"
  "\n"
  "    requestResult = this._database._connection.PUT(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/properties\", JSON.stringify(body));\n"
  "\n"
  "    TRI_CheckRequestResult(requestResult);\n"
  "  }\n"
  "\n"
  "  return { \n"
  "    waitForSync : requestResult.waitForSync,\n"
  "    journalSize : requestResult.journalSize\n"
  "  };\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief gets the figures of a collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.figures = function () {\n"
  "  var requestResult = this._database._connection.GET(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/figures\");\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return requestResult.figures;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief drops a collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.drop = function () {\n"
  "  var requestResult = this._database._connection.DELETE(\"/_api/collection/\" + encodeURIComponent(this._id));\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  this._status = AvocadoCollection.STATUS_DELETED;\n"
  "\n"
  "  var database = this._database;\n"
  "\n"
  "  for (var name in database) {\n"
  "    if (database.hasOwnProperty(name)) {\n"
  "      var collection = database[name];\n"
  "\n"
  "      if (collection instanceof AvocadoCollection) {\n"
  "        if (collection._id == this._id) {\n"
  "          delete database[name];\n"
  "        }\n"
  "      }\n"
  "    }\n"
  "  }\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief truncates a collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.truncate = function () {\n"
  "  var requestResult = this._database._connection.PUT(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/truncate\", \"\");\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  this._status = null;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief loads a collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.load = function () {\n"
  "  var requestResult = this._database._connection.PUT(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/load\", \"\");\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  this._status = null;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief unloads a collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.unload = function () {\n"
  "  var requestResult = this._database._connection.PUT(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/unload\", \"\");\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  this._status = null;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief renames a collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.rename = function (name) {\n"
  "  var body = { name : name };\n"
  "  var requestResult = this._database._connection.PUT(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/rename\", JSON.stringify(body));\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  delete this._database[this._name];\n"
  "  this._database[name] = this;\n"
  "\n"
  "  this._status = null;\n"
  "  this._name = null;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief refreshes a collection status and name\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.refresh = function () {\n"
  "  var requestResult = this._database._connection.GET(\"/_api/collection/\" + encodeURIComponent(this._id));\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  this._name = requestResult['name'];\n"
  "  this._status = requestResult['status'];\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                document functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief returns the number of documents\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.count = function () {\n"
  "  var requestResult = this._database._connection.GET(\"/_api/collection/\" + encodeURIComponent(this._id) + \"/count\");\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return requestResult[\"count\"];\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return all documents from the collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.all = function () {\n"
  "  var data = {\n"
  "    collection : this._id\n"
  "  }  \n"
  "  \n"
  "  var requestResult = this._database._connection.PUT(\"/_api/simple/all\", JSON.stringify(data));\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return requestResult;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return a single document from the collection, identified by its id\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.document = function (id) {\n"
  "  var rev = null;\n"
  "  var requestResult;\n"
  "\n"
  "  if (id.hasOwnProperty(\"_id\")) {\n"
  "    if (id.hasOwnProperty(\"_rev\")) {\n"
  "      rev = id._rev;\n"
  "    }\n"
  "\n"
  "    id = id._id;\n"
  "  }\n"
  "\n"
  "  if (rev == null) {\n"
  "    requestResult = this._database._connection.GET(\"/document/\" + id);\n"
  "  }\n"
  "  else {\n"
  "    requestResult = this._database._connection.GET(\"/document/\" + id, {'if-match' : '\"' + rev + '\"' });\n"
  "  }\n"
  "\n"
  "  if (requestResult != null\n"
  "      && requestResult.error == true \n"
  "      && requestResult.errorNum == internal.errors.ERROR_AVOCADO_COLLECTION_NOT_FOUND.code) {\n"
  "    var s = id.split(\"/\");\n"
  "\n"
  "    if (s.length != 2) {\n"
  "      requestResult.errorNum = internal.errors.ERROR_AVOCADO_DOCUMENT_HANDLE_BAD.code;\n"
  "    }\n"
  "    else if (s[0] != this._id) {\n"
  "      requestResult.errorNum = internal.errors.ERROR_AVOCADO_CROSS_COLLECTION_REQUEST.code;\n"
  "    }\n"
  "\n"
  "    throw new AvocadoError(requestResult);\n"
  "  }\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return requestResult;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief save a document in the collection, return its id\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.save = function (data) {    \n"
  "  var requestResult = this._database._connection.POST(\"/document?collection=\" + encodeURIComponent(this._id), JSON.stringify(data));\n"
  "  \n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return requestResult;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief delete a document in the collection, identified by its id\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.remove = function (id, overwrite) {\n"
  "  var rev = null;\n"
  "  var requestResult;\n"
  "\n"
  "  if (id.hasOwnProperty(\"_id\")) {\n"
  "    if (id.hasOwnProperty(\"_rev\")) {\n"
  "      rev = id._rev;\n"
  "    }\n"
  "\n"
  "    id = id._id;\n"
  "  }\n"
  "\n"
  "  var policy = \"\";\n"
  "\n"
  "  if (overwrite) {\n"
  "    policy = \"?policy=last\";\n"
  "  }\n"
  "\n"
  "  if (rev == null) {\n"
  "    requestResult = this._database._connection.DELETE(\"/document/\" + id + policy);\n"
  "  }\n"
  "  else {\n"
  "    requestResult = this._database._connection.DELETE(\"/document/\" + id + policy, {'if-match' : '\"' + rev + '\"' });\n"
  "  }\n"
  "\n"
  "  if (requestResult != null && requestResult.error == true) {\n"
  "    var s = id.split(\"/\");\n"
  "\n"
  "    if (s.length != 2) {\n"
  "      requestResult.errorNum = internal.errors.ERROR_AVOCADO_DOCUMENT_HANDLE_BAD.code;\n"
  "    }\n"
  "    else if (s[0] != this._id) {\n"
  "      requestResult.errorNum = internal.errors.ERROR_AVOCADO_CROSS_COLLECTION_REQUEST.code;\n"
  "    }\n"
  "\n"
  "    if (overwrite) {\n"
  "      if (requestResult.errorNum == internal.errors.ERROR_AVOCADO_DOCUMENT_NOT_FOUND.code) {\n"
  "        return false;\n"
  "      }\n"
  "    }\n"
  "\n"
  "    throw new AvocadoError(requestResult);\n"
  "  }\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return true;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief update a document in the collection, identified by its id\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoCollection.prototype.replace = function (id, data, overwrite) { \n"
  "  var rev = null;\n"
  "  var requestResult;\n"
  "\n"
  "  if (id.hasOwnProperty(\"_id\")) {\n"
  "    if (id.hasOwnProperty(\"_rev\")) {\n"
  "      rev = id._rev;\n"
  "    }\n"
  "\n"
  "    id = id._id;\n"
  "  }\n"
  "\n"
  "  var policy = \"\";\n"
  "\n"
  "  if (overwrite) {\n"
  "    policy = \"?policy=last\";\n"
  "  }\n"
  "\n"
  "  if (rev == null) {\n"
  "    requestResult = this._database._connection.PUT(\"/document/\" + id + policy, JSON.stringify(data));\n"
  "  }\n"
  "  else {\n"
  "    requestResult = this._database._connection.PUT(\"/document/\" + id + policy, JSON.stringify(data), {'if-match' : '\"' + rev + '\"' });\n"
  "  }\n"
  "\n"
  "  if (requestResult != null && requestResult.error == true) {\n"
  "    var s = id.split(\"/\");\n"
  "\n"
  "    if (s.length != 2) {\n"
  "      requestResult.errorNum = internal.errors.ERROR_AVOCADO_DOCUMENT_HANDLE_BAD.code;\n"
  "    }\n"
  "    else if (s[0] != this._id) {\n"
  "      requestResult.errorNum = internal.errors.ERROR_AVOCADO_CROSS_COLLECTION_REQUEST.code;\n"
  "    }\n"
  "\n"
  "    throw new AvocadoError(requestResult);\n"
  "  }\n"
  "\n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return requestResult;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                            AvocadoEdgesCollection\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                      constructors and destructors\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief constructor\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function AvocadoEdgesCollection (database, data) {\n"
  "  this._database = database;\n"
  "\n"
  "  if (typeof data === \"string\") {\n"
  "    this._name = data;\n"
  "  }\n"
  "  else {\n"
  "    this._id = data.id;\n"
  "    this._name = data.name;\n"
  "    this._status = data.status;\n"
  "  }\n"
  "}\n"
  "\n"
  "AvocadoEdgesCollection.prototype = new AvocadoCollection();\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                 private functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief help for AvocadoCollection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "helpAvocadoEdgesCollection = TRI_CreateHelpHeadline(\"AvocadoEdgesCollection help\") +\n"
  "'AvocadoEdgesCollection constructor:                                 ' + \"\\n\" +\n"
  "' > col = edges.mycoll;                                              ' + \"\\n\" +\n"
  "' > col = db._create(\"mycoll\");                                      ' + \"\\n\" +\n"
  "'                                                                    ' + \"\\n\" +\n"
  "'Attributes:                                                         ' + \"\\n\" +\n"
  "'  _database                       database object                   ' + \"\\n\" +\n"
  "'  _id                             collection identifier             ';\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return a string representation of the collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoEdgesCollection.prototype.toString = function () {  \n"
  "  return TRI_GetIdString(this, \"AvocadoEdgesCollection\");\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief prints the collection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoEdgesCollection.prototype._PRINT = function () {  \n"
  "  var status = \"unknown\";\n"
  "\n"
  "  switch (this.status()) {\n"
  "    case AvocadoCollection.STATUS_NEW_BORN: status = \"new born\"; break;\n"
  "    case AvocadoCollection.STATUS_UNLOADED: status = \"unloaded\"; break;\n"
  "    case AvocadoCollection.STATUS_UNLOADING: status = \"unloading\"; break;\n"
  "    case AvocadoCollection.STATUS_LOADED: status = \"loaded\"; break;\n"
  "    case AvocadoCollection.STATUS_CORRUPTED: status = \"corrupted\"; break;\n"
  "    case AvocadoCollection.STATUS_DELETED: status = \"deleted\"; break;\n"
  "  }\n"
  "  \n"
  "  internal.output(\"[AvocadoEdgesCollection \", this._id, \", \\\"\", this.name(), \"\\\" (status \" + status + \")]\");\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief print the help for AvocadoCollection\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoEdgesCollection.prototype._help = function () {  \n"
  "  print(helpAvocadoEdgesCollection);\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                document functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief save a document in the collection, return its id\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoEdgesCollection.prototype.save = function (from, to, data) {    \n"
  "  if (from.hasOwnProperty(\"_id\")) {\n"
  "    from = from._id;\n"
  "  }\n"
  "\n"
  "  if (to.hasOwnProperty(\"_id\")) {\n"
  "    to = to._id;\n"
  "  }\n"
  "\n"
  "  var url = \"/edge?collection=\" + encodeURIComponent(this._id)\n"
  "          + \"&from=\" + encodeURIComponent(from)\n"
  "          + \"&to=\" + encodeURIComponent(to);\n"
  "\n"
  "  var requestResult = this._database._connection.POST(url, JSON.stringify(data));\n"
  "  \n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return requestResult;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief returns the edges starting or ending in a vertex\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoEdgesCollection.prototype.edges = function (vertex) {\n"
  "\n"
  "  // if vertex is a list, iterator and concat\n"
  "  if (vertex instanceof Array) {\n"
  "    var edges = [];\n"
  "\n"
  "    for (var i = 0;  i < vertex.length;  ++i) {\n"
  "      var e = this.edges(vertex[i]);\n"
  "      \n"
  "      edges.push.apply(edges, e);\n"
  "    }\n"
  "\n"
  "    return edges;\n"
  "  }\n"
  "\n"
  "  if (vertex.hasOwnProperty(\"_id\")) {\n"
  "    vertex = vertex._id;\n"
  "  }\n"
  "\n"
  "  // get the edges\n"
  "  requestResult = this._database._connection.GET(\"/edges/\" + encodeURIComponent(this._id) + \"?vertex=\" + encodeURIComponent(vertex));\n"
  "  \n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return requestResult['edges'];\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief returns the edges ending in a vertex\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoEdgesCollection.prototype.inEdges = function (vertex) {\n"
  "\n"
  "  // if vertex is a list, iterator and concat\n"
  "  if (vertex instanceof Array) {\n"
  "    var edges = [];\n"
  "\n"
  "    for (var i = 0;  i < vertex.length;  ++i) {\n"
  "      var e = this.inEdges(vertex[i]);\n"
  "      \n"
  "      edges.push.apply(edges, e);\n"
  "    }\n"
  "\n"
  "    return edges;\n"
  "  }\n"
  "\n"
  "  if (vertex.hasOwnProperty(\"_id\")) {\n"
  "    vertex = vertex._id;\n"
  "  }\n"
  "\n"
  "  // get the edges\n"
  "  requestResult = this._database._connection.GET(\"/edges/\" + encodeURIComponent(this._id) + \"?direction=in&vertex=\" + encodeURIComponent(vertex));\n"
  "  \n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return requestResult['edges'];\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief returns the edges starting in a vertex\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoEdgesCollection.prototype.outEdges = function (vertex) {\n"
  "\n"
  "  // if vertex is a list, iterator and concat\n"
  "  if (vertex instanceof Array) {\n"
  "    var edges = [];\n"
  "\n"
  "    for (var i = 0;  i < vertex.length;  ++i) {\n"
  "      var e = this.outEdges(vertex[i]);\n"
  "      \n"
  "      edges.push.apply(edges, e);\n"
  "    }\n"
  "\n"
  "    return edges;\n"
  "  }\n"
  "\n"
  "  if (vertex.hasOwnProperty(\"_id\")) {\n"
  "    vertex = vertex._id;\n"
  "  }\n"
  "\n"
  "  // get the edges\n"
  "  requestResult = this._database._connection.GET(\"/edges/\" + encodeURIComponent(this._id) + \"?direction=out&vertex=\" + encodeURIComponent(vertex));\n"
  "  \n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return requestResult['edges'];\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                AvocadoQueryCursor\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                      constructors and destructors\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief constructor\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function AvocadoQueryCursor (database, data) {\n"
  "  this._database = database;\n"
  "  this.data = data;\n"
  "  this._hasNext = false;\n"
  "  this._hasMore = false;\n"
  "  this._pos = 0;\n"
  "  this._count = 0;\n"
  "  this._total = 0;\n"
  "  \n"
  "  if (data.result != undefined) {\n"
  "    this._count = data.result.length;\n"
  "    \n"
  "    if (this._pos < this._count) {\n"
  "      this._hasNext = true;\n"
  "    }\n"
  "    \n"
  "    if (data.hasMore != undefined && data.hasMore) {\n"
  "      this._hasMore = true;\n"
  "    }    \n"
  "  }\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                 private functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief help for AvocadoQueryCursor\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "helpAvocadoQueryCursor = TRI_CreateHelpHeadline(\"AvocadoQueryCursor help\") +\n"
  "'AvocadoQueryCursor constructor:                                     ' + \"\\n\" +\n"
  "' > cu1 = qi1.execute();                                             ' + \"\\n\" +\n"
  "'Functions:                                                          ' + \"\\n\" +\n"
  "'  hasMore();                            returns true if there       ' + \"\\n\" +\n"
  "'                                        are more results            ' + \"\\n\" +\n"
  "'  next();                               returns the next document   ' + \"\\n\" +\n"
  "'  elements();                           returns all documents       ' + \"\\n\" +\n"
  "'  _help();                              this help                   ' + \"\\n\" +\n"
  "'Attributes:                                                         ' + \"\\n\" +\n"
  "'  _database                             database object             ' + \"\\n\" +\n"
  "'Example:                                                            ' + \"\\n\" +\n"
  "' > st = db._createStatement({ \"query\" : \"select a from colA a\" });  ' + \"\\n\" +\n"
  "' > c = st.execute();                                                ' + \"\\n\" +\n"
  "' > documents = c.elements();                                        ' + \"\\n\" +\n"
  "' > c = st.execute();                                                ' + \"\\n\" +\n"
  "' > while (c.hasNext()) { print( c.next() ); }                       ';\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief print the help for the cursor\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoQueryCursor.prototype._help = function () {\n"
  "  print(helpAvocadoQueryCursor);\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return a string representation of the cursor\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoQueryCursor.prototype.toString = function () {  \n"
  "  return TRI_GetIdString(this, \"AvocadoQueryCursor\");\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                  public functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return whether there are more results available in the cursor\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoQueryCursor.prototype.hasNext = function () {\n"
  "  return this._hasNext;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return the next result document from the cursor\n"
  "///\n"
  "/// If no more results are available locally but more results are available on\n"
  "/// the server, this function will make a roundtrip to the server\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoQueryCursor.prototype.next = function () {\n"
  "  if (!this._hasNext) {\n"
  "    throw \"No more results\";\n"
  "  }\n"
  " \n"
  "  var result = this.data.result[this._pos];\n"
  "  this._pos++;\n"
  "    \n"
  "  // reached last result\n"
  "  if (this._pos == this._count) {\n"
  "    this._hasNext = false;\n"
  "    this._pos = 0;\n"
  "    \n"
  "    if (this._hasMore && this.data._id) {\n"
  "      this._hasMore = false;\n"
  "      \n"
  "      // load more results      \n"
  "      var requestResult = this._database._connection.PUT(\"/_api/cursor/\"+ encodeURIComponent(this.data._id),  \"\");\n"
  "    \n"
  "      TRI_CheckRequestResult(requestResult);\n"
  "      \n"
  "      this.data = requestResult;\n"
  "      this._count = requestResult.result.length;\n"
  "    \n"
  "      if (this._pos < this._count) {\n"
  "        this._hasNext = true;\n"
  "      }\n"
  "    \n"
  "      if (requestResult.hasMore != undefined && requestResult.hasMore) {\n"
  "        this._hasMore = true;\n"
  "      }                \n"
  "    }    \n"
  "  }\n"
  "    \n"
  "  return result;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return all remaining result documents from the cursor\n"
  "///\n"
  "/// If no more results are available locally but more results are available on\n"
  "/// the server, this function will make one or multiple roundtrips to the \n"
  "/// server. Calling this function will also fully exhaust the cursor.\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoQueryCursor.prototype.elements = function () {  \n"
  "  var result = [];\n"
  "  \n"
  "  while (this.hasNext()) { \n"
  "    result.push( this.next() ); \n"
  "  }\n"
  "  \n"
  "  return result;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief explicitly dispose the cursor\n"
  "///\n"
  "/// Calling this function will mark the cursor as deleted on the server. It will\n"
  "/// therefore make a roundtrip to the server. Using a cursor after it has been\n"
  "/// disposed is considered a user error\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoQueryCursor.prototype.dispose = function () {\n"
  "  if (!this.data._id) {\n"
  "    // client side only cursor\n"
  "    return;\n"
  "  }\n"
  "\n"
  "  var requestResult = this._database._connection.DELETE(\"/_api/cursor/\"+ encodeURIComponent(this.data._id), \"\");\n"
  "    \n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  this.data._id = undefined;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return the total number of documents in the cursor\n"
  "///\n"
  "/// The number will remain the same regardless how much result documents have\n"
  "/// already been fetched from the cursor.\n"
  "///\n"
  "/// This function will return the number only if the cursor was constructed \n"
  "/// with the \"doCount\" attribute. Otherwise it will return undefined.\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoQueryCursor.prototype.count = function () {\n"
  "  if (!this.data._id) {\n"
  "    throw \"cursor has been disposed\";\n"
  "  }\n"
  "\n"
  "  return this.data.count;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                  AvocadoStatement\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                      constructors and destructors\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief constructor\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "function AvocadoStatement (database, data) {\n"
  "  this._database = database;\n"
  "  this._doCount = false;\n"
  "  this._batchSize = null;\n"
  "  this._bindVars = {};\n"
  "  \n"
  "  if (!(data instanceof Object)) {\n"
  "    throw \"AvocadoStatement needs initial data\";\n"
  "  }\n"
  "    \n"
  "  if (data.query == undefined || data.query == \"\") {\n"
  "    throw \"AvocadoStatement needs a valid query attribute\";\n"
  "  }\n"
  "  this.setQuery(data.query);\n"
  "\n"
  "  if (data.count != undefined) {\n"
  "    this.setCount(data.count);\n"
  "  }\n"
  "  if (data.batchSize != undefined) {\n"
  "    this.setBatchSize(data.batchSize);\n"
  "  }\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                 private functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief help for AvocadoStatement\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "helpAvocadoStatement = TRI_CreateHelpHeadline(\"AvocadoStatement help\") +\n"
  "'AvocadoStatement constructor:                                       ' + \"\\n\" +\n"
  "' > st = new AvocadoStatement({ \"query\" : \"select...\" });            ' + \"\\n\" +\n"
  "' > st = db._createStatement({ \"query\" : \"select ....\" });           ' + \"\\n\" +\n"
  "'Functions:                                                          ' + \"\\n\" +\n"
  "'  bind(<key>, <value>);          bind single variable               ' + \"\\n\" +\n"
  "'  bind(<values>);                bind multiple variables            ' + \"\\n\" +\n"
  "'  setBatchSize(<max>);           set max. number of results         ' + \"\\n\" +\n"
  "'                                 to be transferred per roundtrip    ' + \"\\n\" +\n"
  "'  setCount(<value>);             set count flag (return number of   ' + \"\\n\" +\n"
  "'                                 results in \"count\" attribute)      ' + \"\\n\" +\n"
  "'  getBatchSize();                return max. number of results      ' + \"\\n\" +\n"
  "'                                 to be transferred per roundtrip    ' + \"\\n\" +\n"
  "'  getCount();                    return count flag (return number of' + \"\\n\" +\n"
  "'                                 results in \"count\" attribute)      ' + \"\\n\" +\n"
  "'  getQuery();                    return query string                ' + \"\\n\" +\n"
  "'  execute();                     execute query and return cursor    ' + \"\\n\" +\n"
  "'  _help();                       this help                          ' + \"\\n\" +\n"
  "'Attributes:                                                         ' + \"\\n\" +\n"
  "'  _database                      database object                    ' + \"\\n\" +\n"
  "'Example:                                                            ' + \"\\n\" +\n"
  "' > st = db._createStatement({ \"query\" : \"select a from colA a       ' + \"\\n\" +\n"
  "'                              where a.x = @a@ and a.y = @b@\" });    ' + \"\\n\" +\n"
  "' > st.bind(\"a\", \"hello\");                                           ' + \"\\n\" +\n"
  "' > st.bind(\"b\", \"world\");                                           ' + \"\\n\" +\n"
  "' > c = st.execute();                                                ' + \"\\n\" +\n"
  "' > print(c.elements());                                             ';\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief print the help for AvocadoStatement\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoStatement.prototype._help = function () {\n"
  "  print(helpAvocadoStatement);\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return a string representation of the statement\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoStatement.prototype.toString = function () {  \n"
  "  return TRI_GetIdString(this, \"AvocadoStatement\");\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                  public functions\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @addtogroup AvocadoShell\n"
  "/// @{\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief bind a parameter to the statement\n"
  "///\n"
  "/// This function can be called multiple times, once for each bind parameter.\n"
  "/// All bind parameters will be transferred to the server in one go when \n"
  "/// execute() is called.\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoStatement.prototype.bind = function (key, value) {\n"
  "  if (key instanceof Object) {\n"
  "    if (value != undefined) {\n"
  "      throw \"invalid bind parameter declaration\";\n"
  "    }\n"
  "    this._bindVars = key;\n"
  "  }\n"
  "  else if (typeof(key) == \"string\") {\n"
  "    if (this._bindVars[key] != undefined) {\n"
  "      throw \"redeclaration of bind parameter\";\n"
  "    }\n"
  "    this._bindVars[key] = value;\n"
  "  }\n"
  "  else if (typeof(key) == \"number\") {\n"
  "    var strKey = String(parseInt(key));\n"
  "    if (strKey != String(key)) {\n"
  "      throw \"invalid bind parameter declaration\";\n"
  "    }\n"
  "    if (this._bindVars[strKey] != undefined) {\n"
  "      throw \"redeclaration of bind parameter\";\n"
  "    }\n"
  "    this._bindVars[strKey] = value;\n"
  "  }\n"
  "  else {\n"
  "    throw \"invalid bind parameter declaration\";\n"
  "  }\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief return the bind variables already set\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoStatement.prototype.getBindVariables = function () {\n"
  "  return this._bindVars;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief get the count flag for the statement\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoStatement.prototype.getCount = function () {\n"
  "  return this._doCount;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief get the maximum number of results documents the cursor will return\n"
  "/// in a single server roundtrip.\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoStatement.prototype.getBatchSize = function () {\n"
  "  return this._batchSize;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief get query string\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoStatement.prototype.getQuery = function () {\n"
  "  return this._query;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief set the count flag for the statement\n"
  "///\n"
  "/// Setting the count flag will make the statement's result cursor return the\n"
  "/// total number of result documents. The count flag is not set by default.\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoStatement.prototype.setCount = function (bool) {\n"
  "  this._doCount = bool ? true : false;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief set the maximum number of results documents the cursor will return\n"
  "/// in a single server roundtrip.\n"
  "/// The higher this number is, the less server roundtrips will be made when\n"
  "/// iterating over the result documents of a cursor.\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoStatement.prototype.setBatchSize = function (value) {\n"
  "  if (parseInt(value) > 0) {\n"
  "    this._batchSize = parseInt(value);\n"
  "  }\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief set the query string\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoStatement.prototype.setQuery = function (query) {\n"
  "  this._query = query;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief parse a query and return the results\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoStatement.prototype.parse = function () {\n"
  "  var body = {\n"
  "    \"query\" : this._query,\n"
  "  }\n"
  "\n"
  "  var requestResult = this._database._connection.POST(\"/_api/query\", JSON.stringify(body));\n"
  "    \n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return true;\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief execute the query\n"
  "///\n"
  "/// Invoking execute() will transfer the query and all bind parameters to the\n"
  "/// server. It will return a cursor with the query results in case of success.\n"
  "/// In case of an error, the error will be printed\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "AvocadoStatement.prototype.execute = function () {\n"
  "  var body = {\n"
  "    \"query\" : this._query,\n"
  "    \"count\" : this._doCount,\n"
  "    \"bindVars\" : this._bindVars\n"
  "  }\n"
  "\n"
  "  if (this._batchSize) {\n"
  "    body[\"batchSize\"] = this._batchSize;\n"
  "  }\n"
  "\n"
  "  var requestResult = this._database._connection.POST(\"/_api/cursor\", JSON.stringify(body));\n"
  "    \n"
  "  TRI_CheckRequestResult(requestResult);\n"
  "\n"
  "  return new AvocadoQueryCursor(this._database, requestResult);\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// -----------------------------------------------------------------------------\n"
  "// --SECTION--                                                      initialisers\n"
  "// -----------------------------------------------------------------------------\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief general help\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "HELP = TRI_CreateHelpHeadline(\"Help\") +\n"
  "'Predefined objects:                                                 ' + \"\\n\" +\n"
  "'  avocado:                               AvocadoConnection          ' + \"\\n\" +\n"
  "'  db:                                    AvocadoDatabase            ' + \"\\n\" +\n"
  "'Example:                                                            ' + \"\\n\" +\n"
  "' > db._collections();                    list all collections       ' + \"\\n\" +\n"
  "' > db.<coll_name>.all();                 list all documents         ' + \"\\n\" +\n"
  "' > id = db.<coll_name>.save({ ... });    save a document            ' + \"\\n\" +\n"
  "' > db.<coll_name>.remove(<_id>);         delete a document          ' + \"\\n\" +\n"
  "' > db.<coll_name>.document(<_id>);       get a document             ' + \"\\n\" +\n"
  "' > help                                  show help pages            ' + \"\\n\" +\n"
  "' > helpQueries                           query help                 ' + \"\\n\" +\n"
  "' > exit                                                             ';\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief query help\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "helpQueries = TRI_CreateHelpHeadline(\"Select query help\") +\n"
  "'Create a select query:                                              ' + \"\\n\" +\n"
  "' > st = new AvocadoStatement(db, { \"query\" : \"select...\" });        ' + \"\\n\" +\n"
  "' > st = db._createStatement({ \"query\" : \"select...\" });             ' + \"\\n\" +\n"
  "'Set query options:                                                  ' + \"\\n\" +\n"
  "' > st.setBatchSize(<value>);     set the max. number of results     ' + \"\\n\" +\n"
  "'                                 to be transferred per roundtrip    ' + \"\\n\" +\n"
  "' > st.setCount(<value>);         set count flag (return number of   ' + \"\\n\" +\n"
  "'                                 results in \"count\" attribute)      ' + \"\\n\" +\n"
  "'Get query options:                                                  ' + \"\\n\" +\n"
  "' > st.setBatchSize();            return the max. number of results  ' + \"\\n\" +\n"
  "'                                 to be transferred per roundtrip    ' + \"\\n\" +\n"
  "' > st.getCount();                return count flag (return number of' + \"\\n\" +\n"
  "'                                 results in \"count\" attribute)      ' + \"\\n\" +\n"
  "' > st.getQuery();                return query string                ' + \"\\n\" +\n"
  "'                                 results in \"count\" attribute)      ' + \"\\n\" +\n"
  "'Bind parameters to a query:                                         ' + \"\\n\" +\n"
  "' > st.bind(<key>, <value>);      bind single variable               ' + \"\\n\" +\n"
  "' > st.bind(<values>);            bind multiple variables            ' + \"\\n\" +\n"
  "'Execute query:                                                      ' + \"\\n\" +\n"
  "' > c = st.execute();             returns a cursor                   ' + \"\\n\" +\n"
  "'Get all results in an array:                                        ' + \"\\n\" +\n"
  "' > e = c.elements();                                                ' + \"\\n\" +\n"
  "'Or loop over the result set:                                        ' + \"\\n\" +\n"
  "' > while (c.hasNext()) { print( c.next() ); }                       ';\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief extended help\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "helpExtended = TRI_CreateHelpHeadline(\"More help\") +\n"
  "'Pager:                                                              ' + \"\\n\" +\n"
  "' > internal.stop_pager()               stop the pager output        ' + \"\\n\" +\n"
  "' > internal.start_pager()              start the pager              ' + \"\\n\" +\n"
  "'Pretty printing:                                                    ' + \"\\n\" +\n"
  "' > stop_pretty_print()                 stop pretty printing         ' + \"\\n\" +\n"
  "' > start_pretty_print()                start pretty printing        ' + \"\\n\" +\n"
  "'Color output:                                                       ' + \"\\n\" +\n"
  "' > stop_color_print()                  stop color printing          ' + \"\\n\" +\n"
  "' > start_color_print()                 start color printing         ' + \"\\n\" +\n"
  "' > start_color_print(COLOR_BLUE)       set color                    ' + \"\\n\" +\n"
  "'Print function:                                                     ' + \"\\n\" +\n"
  "' > print(x)                            std. print function          ' + \"\\n\" +\n"
  "' > print_plain(x)                      print without pretty printing' + \"\\n\" +\n"
  "'                                       and without colors           ';\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @brief create the global db object and load the collections\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "try {\n"
  "\n"
  "  // default databases\n"
  "  db = new AvocadoDatabase(avocado);\n"
  "  edges = new AvocadoEdges(avocado);\n"
  "\n"
  "  // load collection data\n"
  "  db._collections();\n"
  "  edges._collections();\n"
  "\n"
  "  // export to internal\n"
  "  ModuleCache[\"/internal\"].exports.db = db;\n"
  "  ModuleCache[\"/internal\"].exports.edges = db;\n"
  "\n"
  "  print(HELP);\n"
  "}\n"
  "catch (err) {\n"
  "  print(err);\n"
  "}\n"
  "\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "/// @}\n"
  "////////////////////////////////////////////////////////////////////////////////\n"
  "\n"
  "// Local Variables:\n"
  "// mode: outline-minor\n"
  "// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\|/// @page\\\\|/// @}\\\\)\"\n"
  "// End:\n"
;
